package com.cskaoyan.kpi.pv;

import com.cskaoyan.kpi.Summary;
import com.cskaoyan.kpi.output.MysqlOutputFormat;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;

import java.io.IOException;

/**
 * @ClassName PV
 * @Description: TODO
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2022/1/19 9:19
 * @Version V1.0
 **/
public class DailyPV {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Configuration configuration = new Configuration(true);
//        configuration.set("mapreduce.app-submission.cross-platform", "true");
        Job job = Job.getInstance(configuration);
//        job.setJar("D:\\ideaProjects\\36th\\mr\\target\\mr-1.0-SNAPSHOT.jar");
        job.setJarByClass(DailyPV.class);
        job.setJobName("dailyPV");
        Path inputPath = new Path(args[0]);
        //最终要输出到mysql，所以不需要配置输出路径
        TextInputFormat.addInputPath(job, inputPath);
        job.addArchiveToClassPath(new Path("/lib/mysql/mysql-connector-java-5.1.47.jar"));
        job.setMapperClass(DailyPVMapper.class);
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(IntWritable.class);

        job.setReducerClass(DailyPVReducer.class);

        job.setOutputKeyClass(Summary.class);
        job.setOutputValueClass(Text.class);
        job.setOutputFormatClass(MysqlOutputFormat.class);

        job.waitForCompletion(true);
    }
}
